<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>仁爱宠物医院</title>
  <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
  <script src="https://unpkg.com/vue@2/dist/vue.js"></script>
  <script src="https://unpkg.com/element-ui/lib/index.js"></script>
  <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
  <link href="https://cdn.staticfile.net/twitter-bootstrap/5.1.1/css/bootstrap.min.css" rel="stylesheet">
  <script src="https://cdn.staticfile.net/twitter-bootstrap/5.1.1/js/bootstrap.bundle.min.js"></script>
  <script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>
  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<style>
  #login {
    width: 100%;
    height: 100vh;
    background: url('../img/login_bg.jpg') no-repeat;
    background-size: 100% 100%;
    overflow: hidden;
  }
</style>

<body>
  <div id="login">
    <div style="background-color: #fff; width: 20%; margin: auto; margin-top: 15%;padding: 3%;text-align: center;">
      <h3>管理员登录</h3>
      <p></p>
      <p></p>
      <form action="#" method="post">
        <label for="account">账号：</label><input type="text" v-model="user.account">
        <p></p>
        <label for="password">密码：</label><input type="password" v-model="user.password">
        <p></p>
        <button type="button" style="border: 0; padding: 10px 20px;" @click="login()">登录</button>
        <p></p>
      </form>
      <a href="./resgister.html">立即注册</a>
    </div>
  </div>
</body>
<script>
  new Vue({
    el: '#login',
    data() {
      return {
        user: {
          account: '',
          password: ''
        }
      }
    },
    created() {
      // 不管有没有登录，进入该页面的时候，进行一下删除id操作，如果用户点击了退出登录，这样就会直接清除掉用户id
      localStorage.removeItem("userId")
    },
    // 方法
    methods: {
      // 登录
      async login() {
        const { data: result } = await this.$http.post('http://localhost:8082/user_backend/login', this.user);
        if (result.flag) {
          // 存入用户的id
          localStorage.setItem("userId", result.data);
          // 跳转到主页
          window.location.href = './home.html';
        } else {
          this.$message.error(result.message)
        }
      }
    }
  });
</script>

</html>